<?php
	include('../../../Connections/conexao.php');
	
	/* EXPRESSÃO PARA EMAIL VÁLIDO */
	if (preg_match("/^([[:alnum:]_.-]){3,}@([[:lower:][:digit:]_.-]{3,})(\.[[:lower:]]{2,3})(\.[[:lower:]]{2})?$/", $_POST['email'])) {
		$email = $_POST['email'];		
	} else {
		$email = "";
	}	
	
	$senha = $_POST['senha'];
	
	if ($email == "") {
		header('Location: ../../../index.php?pg=login&res=failure');
	} else {
		$sql = "SELECT * FROM usuarios";
		$resSql = mysql_query($sql) or die(mysql_error());
		$row = mysql_fetch_assoc($resSql);
		$total = mysql_num_rows($resSql);
		
		do {
			$varEmail = $row['email'];
			$varSenha = $row['senha'];
			
			if ( strcmp($email, $varEmail) == 0 && strcmp($senha, $varSenha) == 0 ) {
				$verificador = 1; // Email existe no banco de dados
				break;
			} else {
				$verificador = 0;
			}
		} while ($row = mysql_fetch_assoc($resSql));
	
		echo '<br>';
		
		if ($verificador == 1) {
			header('Location: ../../../index.php?pg=inicio');

		} else {
			header('Location: ../../../index.php?pg=login&res=failure');
		}
	}

?>